 <%--
  *  File:    VendorCollateEdit.jsp
  *  @Author: Rogerwang
  *  Date:    2006/8/30
  *  @Modifier: Jamesli
  *  Date:    2010/8/8
  *
  *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
  *  All rights reserved.
  *
  *  This software is the confidential and proprietary information of Oval
  *  Technologies, Inc. ("Confidential Information").  You shall not
  *  disclose such Confidential Information and shall use it only in
  *  accordance with the terms of the license agreement you entered into
  *  with Oval.
 --%>



 <%
   //init param
   Category cat = Category.getInstance("jsp.VendorCollateEdit");
   String strTableName = "v_vendorcollateedit";
   String strModuleName = "CM";
   String privilegeCode = "E0163";
   String contextPath = request.getContextPath();
 %>
        <%@ include file="/inc/CommonHeader.inc" %>
       <%@ include file="/inc/OvalLocationDefault.inc" %>

 <%
   //get curuser info
   HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
   String strCurOrgName = (String)CurUserInfo.get("orgname");
   Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
   if(nCurOrgId == null)
   {
     nCurOrgId = new Integer(-1234567);
   }
   
   String  isadmin=(String)CurUserInfo.get("isadmin");
   if(isadmin==null) isadmin="";
 %>




 <html>
 <head>

 <title>VendorCollateEdit</title>
 <PageFlow:CheckPageFlow pageName="p_vendorcollateedit"/>
<%@ include file="/inc/CatchError.inc" %>
 <link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
 <script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
 <script language="JavaScript" src="<%=contextPath %>/js/SummaryDivision.js"></script>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
 <script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
 <script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
 <%@ include file="/inc/SummaryDivision.inc" %>
 <%
   Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
   if(totalsummary == null)
   {
     totalsummary = new Vector();
   }
	String orgoptionvalue = (String)pageContext.getAttribute("orgoption");
	if(orgoptionvalue == null)orgoptionvalue = "1";
 %>
 <script>
 var popwindow;
 function page_summary(actionvalue,orderbyname)
 {
     //if(isEmpty(cform.keyname.value))
     //{
        // alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VendorKey"))%>");
        // return;
    // }


   var editform = summaryPrepare(cform,actionvalue,orderbyname);
   editform.action = "VendorCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=y";
   editform.target = "_self";
   isRunning = true;
   editform.submit();
 }


 function checkAll()
 {
      if(cform.selorgids)
      {
         if(cform.selorgids.length)
         {
             for(var i=0;i<cform.selorgids.length;i++)
             {

                  cform.selorgids[i].checked=cform.selectall.checked;
             }
         }else
         {
             cform.selorgids.checked=cform.selectall.checked;
         }


      }
 }
 function page_update()
 {
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_UPDATE") %>");
    if(!flag)
  return;
  document.cform.action = "VendorCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=u";
   document.cform.target = "_self";
   isRunning = true;
   document.cform.submit();
 }
 
 function page_go()
 {
     if(isNullChecked(cform.selorgids)==true)
   {
       alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
       return;
   }
    if(isEmpty(cform.orgid.value))
     {
         alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CustomerCollateCode"))%>");
         return;
    }
   var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE") %>");
   if(!flag)
     return;

 <%--emptyToNull(document.cform);--%>
 document.cform.action = "VendorCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=s";
   document.cform.target = "_self";
   document.cform.pageaction.value = "OrderBy";
   isRunning = true;
   document.cform.submit();
 }

 var type;

 function page_selectProvince(obj)
 {
   type=obj;
   if(popwindow!=null)
     popwindow.close();
   popwindow = window.open('<%=contextPath %>/masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
 }

 function page_setRegion(code,name)
 {
     var regioncode;
     var regionname;
     var citycode;
     var cityname;
     if(type=='customer')
     {
         regioncode=eval('document.cform.regioncode');
         regionname=eval('document.cform.regionname');
         citycode=eval('document.cform.citycode');
         cityname=eval('document.cform.cityname');
     }
     else
     {
         regioncode=eval('document.cform.sregioncode');
         regionname=eval('document.cform.sregionname');
         citycode=eval('document.cform.scitycode');
         cityname=eval('document.cform.scityname');
     }

     if(code != regioncode.value)
     {
         citycode.value='';
         cityname.value='';
     }

   regioncode.value = code;
   regionname.value = name;
   if (popwindow != null)
     popwindow.close();
 }

 function page_selectCity(obj)
 {
     type=obj;
      var regioncode;
     if(type=='customer')
     {
         regioncode=eval('document.cform.regioncode');
     }
     else
     {
         regioncode=eval('document.cform.sregioncode');
     }
   if(isEmpty(regioncode.value))
   {
     alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
     return;
   }
   if(popwindow!=null)
     popwindow.close();
   popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN' + '&regioncode=' + regioncode.value ,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
 }

 function page_setCity(code,name)
 {
     var citycode;
     var cityname;
     if(type=='customer')
     {
         citycode=eval('document.cform.citycode');
         cityname=eval('document.cform.cityname');
     }
     else
     {
         citycode=eval('document.cform.scitycode');
         cityname=eval('document.cform.scityname');
     }
   citycode.value = code;
   cityname.value = name;
   if (popwindow != null)
     popwindow.close();
 }

 function page_changeRegion(obj)
 {
 	var regioncode = cform.sregioncode.value;
	page_cleanregionandcity();
	if(regioncode == "")return;
    var datahandler = new  DataHandler() ;
    datahandler.add_params("regioncode" , regioncode, 'String') ;
    datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
    datahandler.getResult("regioncode" ,"document.cform.sregioncode");
    datahandler.getResult("regionname" ,"document.cform.sregionname");
    datahandler.add_job("j_getregionbycode");
    datahandler.runDataHandler();
 }

 function page_changeCity(obj)
 {
 	var regioncode = cform.sregioncode.value;
	var citycode = cform.scitycode.value;
	if(isEmpty(regioncode))
	{
	  alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
	  return;
	}
	page_cleancity();
	if(regioncode == "")return;
	var datahandler = new  DataHandler() ;
	datahandler.add_params("regioncode" , regioncode, 'String') ;
	datahandler.add_params("citycode" , citycode, 'String') ;
	datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
	datahandler.getResult("cityname" ,"document.cform.scityname");
	datahandler.getResult("citycode" ,"document.cform.scitycode");
	datahandler.add_job("j_getcitybycode");
	datahandler.runDataHandler();
 }

 function page_cleanregionandcity(){
	cform.sregioncode.value = "";
 	cform.sregionname.value = "";
 	cform.scitycode.value = "";
 	cform.scityname.value = "";
 }

 function page_cleancity(){
 	cform.scityname.value = "";
 	cform.scitycode.value = "";
 }
 
 function page_selectCustomer()
 {
    window.open("<%=contextPath%>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&globalpccodestr=99,112,117", "newwindow", "height=400, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no")
 }
 function page_setOrg(orgid,orgname,orgcode, shortname)
 {
    document.cform.orgid.value=orgid;
    document.cform.orgname.value=orgname;
    document.cform.orgcode.value=orgcode;

 }

 function page_reload()
{
	var orgcode = document.cform.orgcode.value;
   document.cform.orgid.value="";
   document.cform.orgname.value="";
   document.cform.orgcode.value="";
   if(isEmpty(orgcode))
   {
	    document.cform.orgcode.value = "";
	    return;
   }

    var  datahandler = new  DataHandler() ;
    datahandler.add_params("selectoption" , "xjpcustomer") ;
    datahandler.add_params("searchname" , "orgcode") ;
    datahandler.add_params("searchvalue" , orgcode) ;
    datahandler.add_params("orgid" , -1) ;
    datahandler.getResultFromHashMap("orgsummary" ,"orgcode" ,"document.cform.orgcode");
    datahandler.getResultFromHashMap("orgsummary" ,"orgid" ,"document.cform.orgid");
    datahandler.getResultFromHashMap("orgsummary" ,"orgname" ,"document.cform.orgname");
    datahandler.add_job("getrelatedorg") ;
    datahandler.runDataHandler ();
}

function page_upload(){
	this.location.href = "<%= contextPath%>/phap/masterdata/spm/UploadEXL.jsp?first=ZZ&second=ZB01&third=Z0608&<%= OvalTools.randomURL() %>";
}

function page_download(){
	this.location.href = "<%= contextPath%>/phap/masterdata/spm/export/ExportVendorCollate.jsp?scruletype=2&<%= OvalTools.randomURL() %>";
}
 </script>
 </head>


 <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
  <form name="cform" method="post" action="<%=contextPath %>/Dispatcher">
       <input type="hidden" name="pagename" value="p_vendorcollateedit">
       <input type="hidden" name="actionname"/>
       <custom:hidden property="languagecode" scope="session"/>
 <%--  page location   --%>
   <%@ include file="/inc/PageLocation.inc" %>

     <table width="100%" cellspacing="0" cellpadding="0" border="0"  onkeydown="if(event.keyCode==13) page_summary('search');">
         <tr>
             <td width="80%">
            	<table  width="100%" cellspacing="0" cellpadding="0" border="0">
                      <tr>
                       <td width="120">
                           <%= label.getLabelName("L_VendorKey") + label.getLabelName("L_Colon") %>
                       </td>
                       <td>
                           <custom:text property="keyname" size="15"/>
                       </td>
                       <td width="100">
                           <%= label.getLabelName("L_KeyExclude") + label.getLabelName("L_Colon") %>
                       </td>
                       <td>
                           <custom:text property="keynameexc" size="15"/>
                       </td>
                       <%
                              String clstflag = (String)pageContext.getAttribute("clstflag");
                              if(clstflag==null){
                                  clstflag="A";
                              }
                       %>
                     </tr>
                     <tr>
                       <td>
                       	<%= label.getLabelName(" L_DealerProvince") + label.getLabelName("L_Colon") %>
                       </td>
                       <td>
                           <custom:text property="sregioncode"   size="15" onchange="page_changeRegion('supplier')"/>
                           <a onclick="javascript:page_selectProvince('supplier');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                           <custom:text property="sregionname"   size="20" readonly="true"/>
                       </td>
                       <td>
                           <%= label.getLabelName(" L_DealerCity") + label.getLabelName("L_Colon") %>
                       </td>
                       <td>
                           <custom:text property="scitycode"   size="15" onchange="page_changeCity('supplier')"/>
                           <a onclick="javascript:page_selectCity('supplier');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                           <custom:text property="scityname"   size="20" readonly="true" />
                       </td>
                     </tr>
                </table>
                <table>
                      	<%@ include file="/inc/SummarySearch.inc" %>
             	</table>													
             </td>
   			<td width="20%">
   				<table>
   					<tr>
   						<td><input name="clstflag" type="radio" class="normalradio" value="A" <%=clstflag.equalsIgnoreCase("A")?"checked":""%>>
                    	<%= label.getLabelName(" L_AllVendorList") %>
   						</td>
   						<td>&nbsp;</td>
   					</tr>
   					<tr>
   						<td><input name="clstflag" type="radio" class="normalradio" value="V" <%=clstflag.equalsIgnoreCase("V")?"checked":""%>>
                     	<%= label.getLabelName(" L_Auto_CustomerList") %>
   						</td>
   						<td>&nbsp;</td>
   					</tr>
   					<tr>
   						<td><input name="clstflag" type="radio" class="normalradio" value="S" <%=clstflag.equalsIgnoreCase("S")?"checked":""%>>
                    	<%= label.getLabelName(" L_StandardCustoms") %>
   						</td>
   						<td>&nbsp;</td>
   					</tr>
   				</table>
              </td>
           </tr>
           <tr>
             <td colspan="2">
              <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
                 <tr class="deepblue-left">
                     <td class="title_center">
                         <input type="checkbox" name="selectall" onclick="checkAll()" style="border:0">
                     </td>
                   <%if(orgoptionvalue.equals("2")){ %>
                   <td class="title_center"><a href="javascript:page_summary('orderby','originvendorcode')"><%= label.getLabelName("L_OriginVendorCode") %></a></td>
                   <%}else{ %>
                   <td class="title_center"><a href="javascript:page_summary('orderby','originvendorname')"><%= label.getLabelName("L_OriginVendorName") %></a></td>
                   <%} %>
                   <td class="title_center"><a href="javascript:page_summary('orderby','vendorcolcode')"><%= label.getLabelName("L_VendorCollateCode") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','vendorcolname')"><%= label.getLabelName("L_VendorCollateName") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','saleschannelname')"><%= label.getLabelName("L_SaleChannel") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','dealername')"><%= label.getLabelName("L_DealerName") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','sregionname')"><%= label.getLabelName("L_DealerProvince") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','scityname')"><%= label.getLabelName("L_DealerCity") %></a></td>
                    <td class="title_center"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_ActivityStatus") %></a></td>
                 </tr>
                 <%
                        String strClassType="";
                         int i = 0;
                 %>
                 <logic:iterate id="info" collection="<%= totalsummary %>" >
                 <%//show different colours in turns
                     if(i%2 == 1)
                         {
                             strClassType = "td-listrom";
                         }else{
                             strClassType = "none";
                         }
                     i++;
                 %>
                     <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%= strClassType %>'"   class="<%= strClassType %>">
                         <td class="title_center"><custom:checkbox property="orgcollateid" name="info" changedName="selorgids" style="border:0"/></td>
                         <%if(orgoptionvalue.equals("2")){ %>
                         <td>&nbsp;<custom:write  name="info" property="originvendorcode"/></td>
                         <%}else{ %>
                         <td>&nbsp;<custom:write  name="info" property="originvendorname"/></td>
                         <%} %>
                         <td>&nbsp;<custom:write name="info" property="vendorcolcode"/></td>
                         <td>&nbsp;<custom:write name="info" property="vendorcolname"/></td>
                         <td>&nbsp;<custom:write name="info" property="saleschannelname"/></td>
                         <td>&nbsp;<custom:write name="info" property="dealername"/></td>
                         <td>&nbsp;<custom:write name="info" property="sregionname"/></td>
                         <td>&nbsp;<custom:write name="info" property="scityname"/></td>
                         <td>&nbsp;<custom:write name="info" property="statusname"/></td>
                     </tr>
                  </logic:iterate>
                 <%@ include file="/inc/SummaryAction.inc" %>
               </table>
            </td>
       </tr>
       <tr>
         <td>
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td class="summary_top" ></td>
             </tr>
             <tr>
                 <td>
                 	<%if(i > 0){ %>
                         <%= label.getLabelName("L_VendorCollateCode") + label.getLabelName("L_Colon") %>
                     <custom:hidden property="orgid"/>
                     <custom:text property="orgcode" onchange="page_reload()" size="15"/>
                      <custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" onclick="page_selectCustomer()"/>
                     <custom:text property="orgname"  readonly="true" size="25"/>
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<custom:button label="L_Submit" styleClass="button1" style="width:60px;" onclick="page_go()"/>
                    &nbsp; &nbsp;   <custom:button label="L_InstantModify" styleClass="button1" style="width:80px;" onclick="page_update()"/>
                    <%}else{ %>
                    	&nbsp;
                    <%} %>
                    <custom:button label="L_Upload" styleClass="button1" style="width:80px;" onclick="page_upload()"/>
                    <custom:button label="L_Download" styleClass="button1" style="width:80px;" onclick="page_download()"/>
                 </td>
               </tr>
           </table>
         </td>
     </tr>
     <tr>
         <td>&nbsp;</td>
     </tr>


 </table>
 </form>
 </body>
 </html>


